#include "sqlist.h"

void swap(ElemType* a, ElemType* b) {
    ElemType temp = *a;
    *a = *b;
    *b = temp;
}

bool ReverseList(SqList* L, int start, int end) {
    if (start < 0 || end >= L->length || start >= end) {
        return false;
    }
    for (int i = start, j = end; i < j; ++i, --j) {
        swap(&L->data[i], &L->data[j]);
    }
    return true;
}

void RightShift(SqList* L, int k) {
    k %= L->length;
    ReverseList(L, 0, L->length - 1);
    ReverseList(L, 0, k - 1);
    ReverseList(L, k, L->length - 1);
}

int main() {
    SqList la;

    ElemType a[] = {1, 2, 3, 4, 5, 6, 7};

    CreateList(&la, a, 7);
    PrintList(&la);

    RightShift(&la, 2);
    PrintList(&la);

    return 0;
}